package database;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import data.Appointment;
import data.Meeting;
import data.Message;
import data.User;
import data.room.Reservation;
import data.room.Room;

import mockup.MessageMockup;
import mockup.MockupFactory;
import server.database.ConnectionDatabase;

public class DataHandler {

	public static AppoitmentDB appointment = new AppoitmentDB();
	public static LoginDB login = new LoginDB();
	public static MeetingDB meeting = new MeetingDB();
	public static MessageDB message = new MessageDB();
	public static ReservationDB reservation = new ReservationDB();
	public static RoomDB room = new RoomDB();
	public static SettingDB setting = new SettingDB();
	public static UserDB user = new UserDB();

	public static void runAfterConnect() {

		if(user.getAll().size() == 0) {
			System.out.println("Creating users..");

			User usera = new User();
			usera.setName("p");
			usera.setEmail("awsm@a.no");
			usera.setDateOfBirth(new GregorianCalendar());

			usera.setId(DataHandler.user.insert(MockupFactory.getUserMockup(usera)));
			setting.insert(MockupFactory.getUserMockup(usera), "pat", 1, 1);

			User usere = new User();
			usere.setName("m");
			usere.setEmail("awsm@a.no");
			usere.setDateOfBirth(new GregorianCalendar());

			usere.setId(DataHandler.user.insert(MockupFactory.getUserMockup(usere)));
			setting.insert(MockupFactory.getUserMockup(usere), "mer", 1, 1);

			User userd = new User();
			userd.setName("f");
			userd.setEmail("awsm@a.no");
			userd.setDateOfBirth(new GregorianCalendar());

			userd.setId(DataHandler.user.insert(MockupFactory.getUserMockup(userd)));
			setting.insert(MockupFactory.getUserMockup(userd), "fre", 1, 1);

			User userb = new User();
			userb.setName("e");
			userb.setEmail("awsm@b.no");
			userb.setDateOfBirth(new GregorianCalendar());

			userb.setId(DataHandler.user.insert(MockupFactory.getUserMockup(userb)));
			setting.insert(MockupFactory.getUserMockup(userb), "eri", 0, 0);

			User userc = new User();
			userc.setName("d");
			userc.setEmail("awsm@c.no");
			userc.setDateOfBirth(new GregorianCalendar());

			userc.setId(DataHandler.user.insert(MockupFactory.getUserMockup(userc)));
			setting.insert(MockupFactory.getUserMockup(userc), "dan", 0, 0);
			
			System.out.println("Users created");

		}

		if(room.getAll().size() == 0 ) {
			
			System.out.println("Creating rooms..");

			Room roo = new Room();
			roo.setName("RomA");
			roo.setCapacity(7);
			roo.setId(DataHandler.room.insert(MockupFactory.getRoomMockup(roo)));

			Room ro = new Room();
			ro.setName("RomB");
			ro.setCapacity(12);
			ro.setId(DataHandler.room.insert(MockupFactory.getRoomMockup(ro)));

			Room r = new Room();
			r.setName("RomC");
			r.setCapacity(3);
			r.setId(DataHandler.room.insert(MockupFactory.getRoomMockup(r)));
			
			System.out.println("Rooms created");


		}
	}
}
